﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xyz.BusinessObjects;
using Xyz.Service.DataTransferObjects;

namespace Xyz.Service
{
    internal static class Mapper
    {

        #region Administrator

        public static AdministratorDTO ToDto(Administrator obj)
        {
            return new AdministratorDTO
            {
                AdminId = obj.AdminId,
                AdminLoginId = obj.AdminLoginId,
                Password = obj.Password,
                FirstName = obj.FirstName,
                LastName = obj.LastName,
                Gender = obj.Gender,
                DateOfBirth = obj.DateOfBirth
            };
        }

        public static List<AdministratorDTO> ToDto(List<Administrator> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        public static Administrator FromDto(AdministratorDTO obj)
        {
                return new Administrator
                {
                    AdminId = obj.AdminId,
                    AdminLoginId = obj.AdminLoginId,
                    Password = obj.Password,
                    FirstName = obj.FirstName,
                    LastName = obj.LastName,
                    Gender = obj.Gender,
                    DateOfBirth = obj.DateOfBirth,
                };
            
        }

        public static List<Administrator> FromDto(List<AdministratorDTO> obj)
        {
            return obj == null ? null : obj.Select(FromDto).ToList();
        }

        
        #endregion
        #region City

        public static CityDTO ToDto(City obj)
        {
            return new CityDTO
            {
                CityCode = obj.CityCode,
                CountryCode = obj.CountryCode,
                CityName = obj.CityName
            };
        }

        public static List<CityDTO> ToDto(List<City> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        #endregion

        #region Country

        public static CountryDTO ToDto(Country obj)
        {
            return new CountryDTO
            {
                CountryCode = obj.CountryCode,
                CountryName = obj.CountryName
            };
        }

        public static List<CountryDTO> ToDto(List<Country> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        #endregion

        #region Booking

        public static BookingDTO ToDto(Booking obj)
        {
            return new BookingDTO
            {
                AdultNo = obj.AdultNo,
                BookingCode = obj.BookingCode,
                BookingId = obj.BookingId,
                ChildNo = obj.ChildNo,
                ContactEmailAddress = obj.ContactEmailAddress,
                ContactName = obj.ContactName,
                ContactNo = obj.ContactNo,
                PaymentDue = obj.PaymentDue,
                Status = obj.Status,
                TotalTicketFare = obj.TotalTicketFare,
                TripCode = obj.TripCode,
                MemberPayments = ToDto(obj.MemberPayments),
                CardPayments = ToDto(obj.CardPayments),
                BookingDate = obj.BookingDate,
                Tickets = ToDto(obj.Tickets),
                CustomerId = obj.CustomerId
            };
        }

        public static List<BookingDTO> ToDto(List<Booking> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        public static Booking FromDto(BookingDTO obj)
        {
            return new Booking
            {
                AdultNo = obj.AdultNo,
                BookingCode = obj.BookingCode,
                BookingId = obj.BookingId,
                ChildNo = obj.ChildNo,
                ContactEmailAddress = obj.ContactEmailAddress,
                ContactName = obj.ContactName,
                ContactNo = obj.ContactNo,
                PaymentDue = obj.PaymentDue,
                Status = obj.Status,
                TotalTicketFare = obj.TotalTicketFare,
                TripCode = obj.TripCode,
                MemberPayments = FromDto(obj.MemberPayments),
                CardPayments = FromDto(obj.CardPayments),
                BookingDate = obj.BookingDate,
                Tickets = FromDto(obj.Tickets),
                CustomerId = obj.CustomerId
            };
        }

        public static List<Booking> FromDto(List<BookingDTO> obj)
        {
            return obj == null ? null : obj.Select(FromDto).ToList();
        }

        #endregion

        #region CardPayment

        public static CardPaymentDTO ToDto(CardPayment obj)
        {
            return new CardPaymentDTO
            {
                CardExpiryDate = obj.CardExpiryDate,
                CardNo = obj.CardNo,
                CardPaymentId = obj.CardPaymentId,
                CardTypeCode = obj.CardTypeCode,
                NameOnCard = obj.NameOnCard,
                PaidAmount = obj.PaidAmount,
                PaymentMethodCode = obj.PaymentMethodCode
            };
        }

        public static List<CardPaymentDTO> ToDto(List<CardPayment> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        public static List<CardPayment> FromDto(List<CardPaymentDTO> obj)
        {
            return obj == null ? null : obj.Select(FromDto).ToList();
        }

        public static BillingAddress FromDto(BillingAddressDTO obj)
        {
            return new BillingAddress
                       {
                           AddressLine1 = obj.AddressLine1,
                           AddressLine2 = obj.AddressLine2,
                           AddressLine3 = obj.AddressLine3,
                           City = obj.City,
                           Country = obj.Country,
                           PostalCode = obj.PostalCode
                       };
        }

        public static CardPayment FromDto(CardPaymentDTO obj)
        {
            return new CardPayment
            {
                BookingId = obj.BookingId,
                BillingAddress = FromDto(obj.BillingAddress),
                CardExpiryDate = obj.CardExpiryDate,
                CardNo = obj.CardNo,
                CardPaymentId = obj.CardPaymentId,
                CardTypeCode = obj.CardTypeCode,
                NameOnCard = obj.NameOnCard,
                PaidAmount = obj.PaidAmount,
                PaymentMethodCode = obj.PaymentMethodCode
            };
        }

        #endregion

        #region Customer

        public static CustomerDTO ToDto(Customer obj)
        {
            if (obj == null)
                return null;

            if (obj.GetType() == typeof(Member))
            {
                var member = obj as Member;

                return new MemberDTO
                {
                    MemberId = member.MemberId,
                    Address1 = member.Address1,
                    Address2 = member.Address2,
                    Address3 = member.Address3,
                    City = member.City,
                    Country = member.Country,
                    CustomerId = member.CustomerId,
                    DateOfBirth = member.DateOfBirth,
                    FirstName = member.FirstName,
                    Gender = member.Gender,
                    LastName = member.LastName,
                    MemberPoints = member.MemberPoints,
                    PassportExpiryDate = member.PassportExpiryDate,
                    PassportNo = member.PassportNo,
                    Password = member.Password,
                    RoleId = 2,
                    UserName = member.UserName,
                    PostalCode = member.PostalCode//,
                    //Bookings = ToDto(member.Bookings)
                };
            }

            if (obj.GetType() == typeof(Agent))
            {
                var agent = obj as Agent;

                return new AgentDTO
                {
                    AgentId = agent.AgentId,
                    CompanyName = agent.CompanyName,
                    CustomerId = agent.CustomerId,
                    DateOfBirth = agent.DateOfBirth,
                    DiscountRate = agent.DiscountRate,
                    FirstName = agent.FirstName,
                    LastName = agent.LastName,
                    Gender = agent.Gender,
                    Password = agent.Password,
                    RoleId = 1,
                    UserName = agent.UserName
                };
            }

            return null;
        }

        public static List<CustomerDTO> ToDto(List<Customer> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        public static Customer FromDto(CustomerDTO obj)
        {
            if (obj.GetType() == typeof(MemberDTO))
            {
                var member = obj as MemberDTO;

                return new Member
                {
                    MemberId = member.MemberId,
                    Address1 = member.Address1,
                    Address2 = member.Address2,
                    Address3 = member.Address3,
                    City = member.City,
                    Country = member.Country,
                    CustomerId = member.CustomerId,
                    DateOfBirth = member.DateOfBirth,
                    FirstName = member.FirstName,
                    Gender = member.Gender,
                    LastName = member.LastName,
                    MemberPoints = member.MemberPoints,
                    PassportExpiryDate = member.PassportExpiryDate,
                    PassportNo = member.PassportNo,
                    Password = member.Password,
                    RoleId = 2,
                    UserName = member.UserName,
                    PostalCode = member.PostalCode//,
                    //Bookings = FromDto(member.Bookings)
                };
            }

            if (obj.GetType() == typeof(AgentDTO))
            {
                var agent = obj as AgentDTO;

                return new Agent
                {
                    AgentId = agent.AgentId,
                    CompanyName = agent.CompanyName,
                    CustomerId = agent.CustomerId,
                    DateOfBirth = agent.DateOfBirth,
                    DiscountRate = agent.DiscountRate,
                    FirstName = agent.FirstName,
                    LastName = agent.LastName,
                    Gender = agent.Gender,
                    Password = agent.Password,
                    RoleId = 1,
                    UserName = agent.UserName
                };
            }

            return null;
        }

        public static List<Customer> FromDto(List<CustomerDTO> obj)
        {
            return obj == null ? null : obj.Select(FromDto).ToList();
        }

        #endregion

        #region MemberPayment

        public static MemberPaymentDTO ToDto(MemberPayment obj)
        {
            return new MemberPaymentDTO
            {
                BookingId = obj.BookingId,
                MemberId = obj.MemberId,
                PaymentDate = obj.PaymentDate,
                PaymentPoints = obj.PaymentPoints
            };
        }

        public static List<MemberPaymentDTO> ToDto(List<MemberPayment> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        public static List<MemberPayment> FromDto(List<MemberPaymentDTO> obj)
        {
            return obj == null ? null : obj.Select(FromDto).ToList();
        }

        public static MemberPayment FromDto(MemberPaymentDTO obj)
        {
            return new MemberPayment
            {
                BookingId = obj.BookingId,
                MemberId = obj.MemberId,
                PaymentDate = obj.PaymentDate,
                PaymentPoints = obj.PaymentPoints
            };
        }

        #endregion

        #region PaymentMethod

        public static PaymentMethodDTO ToDto(PaymentMethod obj)
        {
            return new PaymentMethodDTO
            {
                PaymentMethodCode = obj.PaymentMethodCode,
                PaymentMethodDescription = obj.PaymentMethodDescription
            };
        }

        public static List<PaymentMethodDTO> ToDto(List<PaymentMethod> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        #endregion

        #region CardType

        public static CardTypeDTO ToDto(CardType obj)
        {
            return new CardTypeDTO
            {
                CardTypeCode = obj.CardTypeCode,
                CardTypeDescription = obj.CardTypeDescription
            };
        }

        public static List<CardTypeDTO> ToDto(List<CardType> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        #endregion

        #region Flight
        public static FlightDTO ToDto(Flight obj)
        {
            return new FlightDTO
            {
                ArrivalAirport = obj.ArrivalAirport,
                ArrivalDateTime = obj.ArrivalDateTime,
                ArrivalTerminal = obj.ArrivalTerminal,
                DepartureAirport = obj.DepartureAirport,
                DepartureDateTime = obj.DepartureDateTime,
                DepartureTerminal = obj.DepartureTerminal,
                Distance = obj.Distance,
                FlightCode = obj.FlightCode,
                FlightId = obj.FlightId,
                FlightStatus = obj.FlightStatus,
                TaxSurcharge = obj.TaxSurcharge,
                AircraftId = obj.AircraftId
            };
        }

        public static List<FlightDTO> ToDto(List<Flight> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        public static Flight FromDto(FlightDTO obj)
        {
            return new Flight
            {
                ArrivalAirport = obj.ArrivalAirport,
                ArrivalDateTime = obj.ArrivalDateTime,
                ArrivalTerminal = obj.ArrivalTerminal,
                DepartureAirport = obj.DepartureAirport,
                DepartureDateTime = obj.DepartureDateTime,
                DepartureTerminal = obj.DepartureTerminal,
                Distance = obj.Distance,
                FlightCode = obj.FlightCode,
                FlightId = obj.FlightId,
                FlightStatus = obj.FlightStatus,
                TaxSurcharge = obj.TaxSurcharge,
                AircraftId = obj.AircraftId
            };
        }
         


        public static List<Flight> FromDto(List<FlightDTO> obj)
        {
            return obj == null ? null : obj.Select(FromDto).ToList();
        }

        #endregion

        #region Ticket

        public static TicketDTO ToDto(Ticket obj)
        {
            return new TicketDTO
                       {
                           BookingId = obj.BookingId,
                           Flight = ToDto(obj.Flight),
                           FlightId = obj.FlightId,
                           FlightSeat = ToDto(obj.FlightSeat),
                           Passenger = ToDto(obj.Passenger),
                           Services = ToDto(obj.Services),
                           TicketFare = obj.TicketFare
                       };
        }

        public static List<TicketDTO> ToDto(List<Ticket> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        public static List<Ticket> FromDto(List<TicketDTO> obj)
        {
            return obj == null ? null : obj.Select(FromDto).ToList();
        }

        public static Ticket FromDto(TicketDTO obj)
        {
            return new Ticket
            {
                BookingId = obj.BookingId,
                Flight = FromDto(obj.Flight),
                FlightId = obj.FlightId,
                FlightSeat = FromDto(obj.FlightSeat),
                Passenger = FromDto(obj.Passenger),
                Services = FromDto(obj.Services),
                TicketFare = obj.TicketFare
            };
        }

        #endregion

        #region AircraftSeat

        public static AircraftSeatDTO ToDto(AircraftSeat obj)
        {
            if (obj == null)
            {
                return null;
            }
            return new AircraftSeatDTO
            {
                AircraftId = obj.AircraftId,
                AircraftSeatId = obj.AircraftSeatId,
                IsAisleSeat = obj.IsAisleSeat,
                IsWindowSeat = obj.IsWindowSeat,
                RewardPoint = obj.RewardPoint,
                SeatColumn = obj.SeatColumn,
                SeatNo = obj.SeatNo,
                SeatRow = obj.SeatRow,
                SeatTypeCode = obj.SeatTypeCode
            };
        }

        public static AircraftSeat FromDto(AircraftSeatDTO obj)
        {
            if (obj == null)
            {
                return null;
            }
            return new AircraftSeat
            {
                AircraftId = obj.AircraftId,
                AircraftSeatId = obj.AircraftSeatId,
                IsAisleSeat = obj.IsAisleSeat,
                IsWindowSeat = obj.IsWindowSeat,
                RewardPoint = obj.RewardPoint,
                SeatColumn = obj.SeatColumn,
                SeatNo = obj.SeatNo,
                SeatRow = obj.SeatRow,
                SeatTypeCode = obj.SeatTypeCode
            };
        }

        public static List<AircraftSeatDTO> ToDto(List<AircraftSeat> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        public static List<AircraftSeat> FromDto(List<AircraftSeatDTO> obj)
        {
            return obj == null ? null : obj.Select(FromDto).ToList();
        }
        #endregion

        #region FlightSeat

        public static FlightSeatDTO ToDto(FlightSeat obj)
        {
            if (obj == null)
            {
                return null;
            }
            return new FlightSeatDTO
            {
                FlightSeatId = obj.FlightSeatId,
                Status = obj.Status,
                AircraftSeatId = obj.AircraftSeatId,
                FlightId = obj.FlightId
                //AircraftSeat = ToDto(obj.AircraftSeat)
            };
        }
        public static FlightSeat FromDto(FlightSeatDTO obj)
        {
            if (obj == null)
            {
                return null;
            }
            return new FlightSeat
            {
                FlightSeatId = obj.FlightSeatId,
                Status = obj.Status,
                AircraftSeatId = obj.AircraftSeatId,
                FlightId = obj.FlightId
                //AircraftSeat = FromDto(obj.AircraftSeat)
            };
        }

        public static List<FlightSeatDTO> ToDto(List<FlightSeat> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        public static List<FlightSeat> FromDto(List<FlightSeatDTO> obj)
        {
            return obj == null ? null : obj.Select(FromDto).ToList();
        }


        #endregion

        #region Passenger

        public static PassengerDTO ToDto(Passenger obj)
        {
            return new PassengerDTO
            {
                ContactNo = obj.ContactNo,
                DateOfBirth = obj.DateOfBirth,
                EmailAddress = obj.EmailAddress,
                FirstName = obj.FirstName,
                TitleCode = obj.TitleCode,
                LastName = obj.LastName,
                PassengerId = obj.PassengerId,
                PassportExpiryDate = obj.PassportExpiryDate,
                PassportNo = obj.PassportNo
            };
        }

        public static Passenger FromDto(PassengerDTO obj)
        {
            return new Passenger
            {
                PassengerId = obj.PassengerId,
                FirstName = obj.FirstName,
                LastName = obj.LastName,
                TitleCode = obj.TitleCode,
                DateOfBirth = obj.DateOfBirth,
                PassportNo = obj.PassportNo,
                PassportExpiryDate = obj.PassportExpiryDate,
                EmailAddress = obj.EmailAddress,
                ContactNo = obj.ContactNo
            };
        }

        #endregion

        #region ServiceCategory

        public static ServiceCategoryDTO ToDto(ServiceCategory obj)
        {
            if (obj == null)
            {
                return null;
            }
            return new ServiceCategoryDTO
            {
                ServiceCategoryCode = obj.ServiceCategoryCode,
                ServiceCategoryDescription = obj.ServiceCategoryDescription
            };
        }

        public static List<ServiceCategoryDTO> ToDto(List<ServiceCategory> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        #endregion

        #region Service



        public static ServiceDTO ToDto(BusinessObjects.Service obj)
        {
            if (obj == null)
            {
                return null;
            }
            return new ServiceDTO
            {
                Price = obj.Price,
                ServiceCode = obj.ServiceCode,
                ServiceDescription = obj.ServiceDescription,
                ServiceCategoryCode = obj.ServiceCategoryCode
            };
        }


        public static BusinessObjects.Service FromDto(ServiceDTO obj)
        {
            if (obj == null)
            {
                return null;
            }
            return new BusinessObjects.Service
            {
                Price = obj.Price,
                ServiceCode = obj.ServiceCode,
                ServiceDescription = obj.ServiceDescription,
                ServiceCategoryCode = obj.ServiceCategoryCode
            };
        }

        public static List<ServiceDTO> ToDto(List<BusinessObjects.Service> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        public static List<BusinessObjects.Service> FromDto(List<ServiceDTO> obj)
        {
            return obj == null ? null : obj.Select(FromDto).ToList();
        }

        public static PassengerServiceDTO ToDto(BusinessObjects.PassengerService obj)
        {
            if (obj == null)
            {
                return null;
            }

            return new PassengerServiceDTO
            {
                TicketId = obj.TicketId,
                ServiceCode = obj.ServiceCode
            };
        }


        public static BusinessObjects.PassengerService FromDto(PassengerServiceDTO obj)
        {
            if (obj == null)
            {
                return null;
            }
            return new BusinessObjects.PassengerService
            {
                TicketId = obj.TicketId,
                ServiceCode = obj.ServiceCode
            };
        }


        public static List<PassengerServiceDTO> ToDto(List<BusinessObjects.PassengerService> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        public static List<BusinessObjects.PassengerService> FromDto(List<PassengerServiceDTO> obj)
        {
            return obj == null ? null : obj.Select(FromDto).ToList();
        }

        #endregion

        #region Title

        public static TitleDTO ToDto(Title obj)
        {
            return new TitleDTO
            {
                TitleCode = obj.TitleCode,
                TitleDescription = obj.TitleDescription
            };
        }

        public static List<TitleDTO> ToDto(List<Title> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        #endregion

        #region Airport

        public static AirportDTO ToDto(Airport obj)
        {
            return new AirportDTO
            {
                AirportCode = obj.AirportCode,
                AirportName = obj.AirportName,
                CityCode = obj.CityCode
            };
        }

        public static List<AirportDTO> ToDto(List<Airport> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        #endregion

        #region Aircraft

        public static AircraftDTO ToDto(Aircraft obj)
        {
            if (obj == null)
            {
                return null;
            }
            return new AircraftDTO
            {
                AircraftId = obj.AircraftId,
                AircraftName = obj.AircraftName,
                TotalRow = obj.TotalRow,
                TotalCol = obj.TotalCol,
                TotalSeat = obj.TotalSeat
            };
        }

        public static List<AircraftDTO> ToDto(List<Aircraft> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        #endregion

        #region Terminal

        public static TerminalDTO ToDto(Terminal obj)
        {
            if (obj == null)
            {
                return null;
            }
            return new TerminalDTO
            {
                TerminalCode = obj.TerminalCode,
                AirportCode = obj.AirportCode,
                TerminalDescription = obj.TerminalDescription
            };
        }

        public static List<TerminalDTO> ToDto(List<Terminal> obj)
        {
            return obj == null ? null : obj.Select(ToDto).ToList();
        }

        #endregion
    }

}
